﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace InternshipManagement.Models
{
    public class CalendarEventRepository
    {
        private InternshipEntities entities = new InternshipEntities();

        public IQueryable<CalendarEvent> FindAllCalendarEvents()
        {
            return entities.CalendarEvents.OrderBy(e => e.StartDate);
        }

        public IQueryable<CalendarEvent> FindAllCalendarEvents(int? UserID)
        {
            return FindAllCalendarEvents().Where(e => (e.UserID == UserID || e.UserID == null));
        }

        public CalendarEvent GetCalendarEvent(int EventID)
        {
            return entities.CalendarEvents.FirstOrDefault(e => e.EventID == EventID);
        }


        public void AddCalendarEvent(CalendarEvent calendarEvent)
        {
            entities.CalendarEvents.AddObject(calendarEvent);
        }

        public void DeleteCalendarEvent(CalendarEvent calendarEvent)
        {
            entities.CalendarEvents.DeleteObject(calendarEvent);
        }


        //
        // Persistence
        public void Save()
        {
            entities.SaveChanges();
        }

    }
}